/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amuthu.indicator;

import com.tictactec.ta.lib.MAType;
import org.amuthu.DataStore;
import org.amuthu.TalibMgr;

/**
 *
 * @author prabhu
 */
public abstract class BollingerIndicator extends Indicator
{
   private int period;
   private double deviations;
   private double upper[];
   private double middle[];
   private double lower[];

   public BollingerIndicator(DataStore dataStore, int period, double deviations, int startOffset)
   {
      super(dataStore, startOffset);
      this.period = period;
      this.deviations = deviations;

      upper = new double[1];
      middle = new double[1];
      lower = new double[1];
   }

   public double getLower()
   {
      return roundDouble(lower[0], 2);
   }

   public double getMiddle()
   {
      return roundDouble(middle[0], 2);
   }

   public double getUpper()
   {
      return roundDouble(upper[0], 2);
   }

   public void doCalculate()
   {
      int lastIdx = getLastIndex();

      TalibMgr.getTalib().bbands(lastIdx,
                                 lastIdx,
                                 getDataStore().getClose(),
                                 period,
                                 deviations,
                                 deviations,
                                 MAType.Sma,
                                 TalibMgr.getOutBeginIdx(),
                                 TalibMgr.getOutNbElement(),
                                 upper,
                                 middle,
                                 lower);
   }

   @Override
   public int getDayDependency()
   {
      return TalibMgr.getTalib().bbandsLookback(period, deviations, deviations, MAType.Sma) + startOffset;
   }

}
